package edu.psu.geovista.app.pcp.plot.control.tools;

import edu.psu.geovista.app.pcp.plot.gui.BasicPcpUI;
import edu.psu.geovista.app.pcp.plot.layer.DynamicLayer;
import edu.psu.geovista.app.plot.axis.YAxis;
import edu.psu.geovista.app.plot.layer.Layer;

import javax.swing.event.MouseInputListener;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.Iterator;

/**
 *
 * User: jinchen
 * Date: Jun 30, 2003
 * Time: 4:13:24 PM
 * To change this template use Options | File Templates.
 */
public abstract class BasicMouseTool extends BasicTool
                            implements MouseInputListener{
    public static final boolean DEBUG =false;
    protected  Point lastp;
    protected  Point cp;//current point
    public BasicMouseTool(BasicPcpUI ui) {
        super(ui);
         cp=new Point();

    }

    public void mousePressed(MouseEvent e) {
    }
     public void mouseDragged(MouseEvent e) {

     }
     public void mouseMoved(MouseEvent e) {
     }
      public void mouseReleased(MouseEvent e) {


         //if(this.isToolOn() )
            this.reset() ;

     }
     public  void reset() {
         this.setActiveAxis(null);
         this.setToolOn(false);
         DynamicLayer dl=(DynamicLayer)ui.getLayer(Layer.DYNAMIC_LAYER );
         dl.reset() ;
         //ui.getPlotCanvas().repaint();
         this.repaintPlot() ;


     }


     public void mouseEntered(MouseEvent e) {}
     public void mouseExited(MouseEvent e) {}
     public void mouseClicked(MouseEvent e) {

     }

    /**
      *  update value of last point and current point
      */
     protected  void updateLCpoint(Point p){
         if (this.lastp ==null){
            lastp=new Point();
            lastp.setLocation(p);
         }
         else
            this.lastp.setLocation(this.cp );
         this.cp.setLocation(p);
     }
    /**
      *  Given a point(x,y), find a axis that contain the point
      */
     public YAxis findActiveAxis(int x, int y){
          Iterator iter=getAxisList().iterator() ;
          while(iter.hasNext() ){
              YAxis axis=(YAxis)iter.next() ;
              if (axis.footerContain(x,y)){
                  return axis;
              }
          }
          return null;
     }

     
}
